Skip to content

TST: Use fixtures in indexes common tests #17622

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 25, 2017

Conversation

GuessWhoSamFoo
Copy link
Contributor

Not sure if there is a better way to define fixture params since they're essentially the indexes defined in setup_method. Also thinking about adding an id to each param so the output doesn't look like:

test_base.py::TestMixedIntIndex::test_sort[index0] <- pandas/tests/indexes/common.py PASSED
test_base.py::TestMixedIntIndex::test_sort[index1] <- pandas/tests/indexes/common.py PASSED
test_base.py::TestMixedIntIndex::test_sort[index2] <- pandas/tests/indexes/common.py PASSED
test_base.py::TestMixedIntIndex::test_sort[index3] <- pandas/tests/indexes/common.py PASSED
...

@@ -29,6 +29,24 @@
from pandas._libs.lib import Timestamp


@pytest.fixture(params=[tm.makeUnicodeIndex(100),
tm.makeStringIndex(100),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move these to a conftest.py in this directory then they can be used in any test files

@jreback jreback added the Testing pandas testing functions or related to the test suite label Sep 22, 2017
@pytest.fixture(params=[tm.makeUnicodeIndex(100),
tm.makeStringIndex(100),
tm.makeDateIndex(100),
tm.makePeriodIndex(100),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you might also want to call the fixture indices to avoid confusion (then in each test that uses you can either rename index -> indices or do a index = indices at the top)

Index([True, False]),
tm.makeCategoricalIndex(100),
Index([]),
MultiIndex.from_tuples(lzip(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can name these by:

ids = lambda x: type(x).__name__

@jreback
Copy link
Contributor

jreback commented Sep 23, 2017

can you update

tm.makeDateIndex(100),
tm.makePeriodIndex(100),
tm.makeTimedeltaIndex(100),
tm.makeIntIndex(100),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should work but i was actually meaning a conftest
in the tests/indexes/conftest.py

these put the fixtures close to the testing code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case this comes up for anyone else, I got confused about the scope of conftest.py until reading this post: https://stackoverflow.com/questions/34466027/in-py-test-what-is-the-use-of-conftest-py-files

@pep8speaks
Copy link

pep8speaks commented Sep 24, 2017

Hello @GuessWhoSamFoo! Thanks for updating the PR.

Cheers ! There are no PEP8 issues in this Pull Request. 🍻

Comment last updated on September 24, 2017 at 22:38 Hours UTC

@codecov
Copy link

codecov bot commented Sep 25, 2017

Codecov Report

Merging #17622 into master will increase coverage by 0.03%.
The diff coverage is 92.85%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #17622      +/-   ##
==========================================
+ Coverage    91.2%   91.23%   +0.03%     
==========================================
  Files         163      163              
  Lines       49637    49806     +169     
==========================================
+ Hits        45269    45442     +173     
+ Misses       4368     4364       -4
Flag Coverage Δ
#multiple 89.03% <92.85%> (+0.06%) ⬆️
#single 40.32% <85.71%> (+0.07%) ⬆️
Impacted Files Coverage Δ
pandas/tests/indexes/conftest.py 96.77% <92.85%> (ø)
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/accessor.py 93.65% <0%> (-6.35%) ⬇️
pandas/core/indexes/category.py 97.74% <0%> (-0.81%) ⬇️
pandas/core/indexes/interval.py 92.85% <0%> (-0.72%) ⬇️
pandas/core/dtypes/common.py 94.45% <0%> (-0.41%) ⬇️
pandas/core/categorical.py 95.28% <0%> (-0.31%) ⬇️
pandas/io/excel.py 80.37% <0%> (-0.18%) ⬇️
pandas/core/frame.py 97.73% <0%> (-0.14%) ⬇️
pandas/io/packers.py 88.19% <0%> (-0.04%) ⬇️
... and 21 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8276a42...6ea1c70. Read the comment docs.

1 similar comment
@codecov
Copy link

codecov bot commented Sep 25, 2017

Codecov Report

Merging #17622 into master will increase coverage by 0.03%.
The diff coverage is 92.85%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #17622      +/-   ##
==========================================
+ Coverage    91.2%   91.23%   +0.03%     
==========================================
  Files         163      163              
  Lines       49637    49806     +169     
==========================================
+ Hits        45269    45442     +173     
+ Misses       4368     4364       -4
Flag Coverage Δ
#multiple 89.03% <92.85%> (+0.06%) ⬆️
#single 40.32% <85.71%> (+0.07%) ⬆️
Impacted Files Coverage Δ
pandas/tests/indexes/conftest.py 96.77% <92.85%> (ø)
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/accessor.py 93.65% <0%> (-6.35%) ⬇️
pandas/core/indexes/category.py 97.74% <0%> (-0.81%) ⬇️
pandas/core/indexes/interval.py 92.85% <0%> (-0.72%) ⬇️
pandas/core/dtypes/common.py 94.45% <0%> (-0.41%) ⬇️
pandas/core/categorical.py 95.28% <0%> (-0.31%) ⬇️
pandas/io/excel.py 80.37% <0%> (-0.18%) ⬇️
pandas/core/frame.py 97.73% <0%> (-0.14%) ⬇️
pandas/io/packers.py 88.19% <0%> (-0.04%) ⬇️
... and 21 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8276a42...6ea1c70. Read the comment docs.

@jreback jreback added this to the 0.21.0 milestone Sep 25, 2017
@jreback jreback merged commit d2b1668 into pandas-dev:master Sep 25, 2017
@jreback
Copy link
Contributor

jreback commented Sep 25, 2017

thanks!

just added about 1000 tests!

ideally would like to add more local conftests as needed similar to this. IOW there are other places where we need fixtures similar to this. things like timeseries offsets and others, if you are interested.

@jreback
Copy link
Contributor

jreback commented Sep 25, 2017

also in pandas/test_base where I think. if you want to search for and make an issue of places to correct would be great (or just send PR's!)

@GuessWhoSamFoo GuessWhoSamFoo deleted the common_fixtures branch September 28, 2017 03:23
alanbato pushed a commit to alanbato/pandas that referenced this pull request Nov 10, 2017
No-Stream pushed a commit to No-Stream/pandas that referenced this pull request Nov 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TST: use fixtures in Index common tests
3 participants